module Enumerable
  def sensible_sort
    sort_by {|k| k.to_s.split(/((?:(?:^|\s)[-+])?(?:\.\d+|\d+(?:\.\d+?(?:[eE]\d+)?(?:$|(?![eE\.])))?))/ms).map {|v| Float(v) rescue v.downcase}}
  end
end

class String
  def paragraphize
    out = ''
    paragraphs = self.split(/\n+/)
    if paragraphs
      paragraphs.each { |s| out << "<p>#{s}</p>" }
    end
    out != '' ? out : self
  end

end


module SulpetUtils

  public

  def validate_cpf cpf

		return false if cpf.size < 11

		digitos = cpf.split('').map { |d| d.to_i }
		[8,9].each do |dig|

		soma = 0
		for i in 0..dig
		  soma += digitos[i] * ((dig+2) - i)
	 	end

		digito = nil
		resto = soma % 11

		if resto < 2
			digito = 0
		else
			digito = 11 - resto
		end

		return false if digitos[dig+1] != digito

		end

		return true

	end

end
